package dk.lector.utils;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

import dk.lector.R;
import android.content.ContentValues;
import android.content.Context;



public class ConfigXMLParser {

	
//	// Content values keys (using column names) from provider-class
//		public static final String _ID = "_id";
//		public static final String SERVER_URL = "server_url";
//		public static final String SSL = "ssl";
//		public static final String MODULUS = "modulus";
//		public static final String EXPONENT = "exponent";
//		public static final String DOMAIN = "domain";
//		public static final String TIMETOKEEP_DOCS = "timetokeep_docs";
//		public static final String TIMETOKEEP_USER = "timetokeep_user";
//		public static final String COMPANY_NAME = "company_name";
//
//	
	
	
	public static ContentValues getValuesFromXML(Context context) {
		ContentValues cv = new ContentValues();
		InputStream stream;
		try {
			stream = context.openFileInput(context
					.getString(R.string.configuration_filename));
			DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
			DocumentBuilder db = dbf.newDocumentBuilder();
			Document doc = db.parse(stream);
			doc.getDocumentElement().normalize();

			Element element = doc.getDocumentElement();
			NodeList list = element.getChildNodes();
			for (int i = 0; i < list.getLength(); i++) {
				Node node = list.item(i);
				if (node != null) {
					if (node.getNodeType() == 1) {
						cv.put(node.getNodeName(), node.getTextContent());
					}
				}
			}

		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ParserConfigurationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SAXException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return cv;
	}
}
